

package com.hazelcast.test.starter.answer;

import org.mockito.invocation.InvocationOnMock;

import static com.hazelcast.test.starter.HazelcastProxyFactory.proxyArgumentsIfNeeded;

public class ServerAnswer extends AbstractAnswer {

    public ServerAnswer(Object delegate) {
        super(delegate);
    }

    @Override
    Object answer(InvocationOnMock invocation, String methodName, Object[] arguments) throws Exception {
        if (arguments.length == 1) {
            if (methodName.equals("getConnectionManager")) {
                arguments = proxyArgumentsIfNeeded(arguments, delegateClassloader);
                Object endpointManager = invokeForMock(invocation, arguments);
                return createMockForTargetClass(endpointManager, new FirewallingConnectionManagerAnswer(endpointManager));
            }
        }
        throw new UnsupportedOperationException("Not implemented: " + invocation);
    }
}
